﻿using System;
using System.ComponentModel.Composition;
using System.Windows;
using MediaAssistant.Data;
using MediaAssistant.EventArguments;
using MefBasic;
using MefBasic.Commans;
using Microsoft.Practices.Composite.Events;

namespace MediaAssistant.Controls.PlayingMusicInfo
{
    [Export]
    public class PlayingMusicInfoPresenter:APresenter<IPlayingMusicInfoView>
    {
        [ImportingConstructor]
        public PlayingMusicInfoPresenter(IPlayingMusicInfoView view, IEventAggregator eventAggregator) : base(view)
        {
            eventAggregator.GetEvent<BaseEvent<PlayingMusicEventArgs>>().Subscribe(HandlePlayingMusicEvent);
        }

        private void HandlePlayingMusicEvent(PlayingMusicEventArgs obj)
        {
            if (obj.Music != null)
            {
                PlayingMusicTitle = string.IsNullOrWhiteSpace(obj.Music.Title) ? obj.Music.FileName : obj.Music.Title;
                PlayingMusicArtist = obj.Music.Artist;
                TimelineVisibility = Visibility.Visible;
            }
            else
            {
                PlayingMusicTitle = string.Empty;
                PlayingMusicArtist = string.Empty;
                TimelineVisibility = Visibility.Hidden;
            }
        }

        [Import]
        public LibraryDataSource DataSource
        {
            get { return (LibraryDataSource)GetValue(DataSourceProperty); }
            set { SetValue(DataSourceProperty, value); }
        }

        public static readonly DependencyProperty DataSourceProperty =
            DependencyProperty.Register("DataSource", typeof(LibraryDataSource), typeof(PlayingMusicInfoPresenter), new UIPropertyMetadata(null));




        public Visibility TimelineVisibility
        {
            get { return (Visibility)GetValue(TimelineVisibilityProperty); }
            set { SetValue(TimelineVisibilityProperty, value); }
        }

        public static readonly DependencyProperty TimelineVisibilityProperty =
            DependencyProperty.Register("TimelineVisibility", typeof(Visibility), typeof(PlayingMusicInfoPresenter), new UIPropertyMetadata(Visibility.Hidden));

        
        public string PlayingMusicArtist
        {
            get { return (string)GetValue(PlayingMusicArtistProperty); }
            set { SetValue(PlayingMusicArtistProperty, value); }
        }

        public static readonly DependencyProperty PlayingMusicArtistProperty =
            DependencyProperty.Register("PlayingMusicArtist", typeof(string), typeof(PlayingMusicInfoPresenter), new UIPropertyMetadata(null));



        public string PlayingMusicTitle
        {
            get { return (string)GetValue(PlayingMusicTitleProperty); }
            set { SetValue(PlayingMusicTitleProperty, value); }
        }

        public static readonly DependencyProperty PlayingMusicTitleProperty =
            DependencyProperty.Register("PlayingMusicTitle", typeof(string), typeof(PlayingMusicInfoPresenter), new UIPropertyMetadata(null));

        
    }
}
